package com.sn.author.monitor.handler;

import com.alibaba.fastjson.JSON;
import com.sn.author.common.context.SpringContext;
import com.sn.author.common.sdk.AbstractResponse;
import com.sn.author.common.sdk.entity.AbstractResult;
import com.sn.author.common.sdk.response.CommentResponse;
import com.sn.author.domain.entity.ImportAccount;
import com.sn.author.domain.entity.JobAccount;
import com.sn.author.domain.taskEntity.TaskModel;
import com.sn.author.service.impl.DyUserServiceImpl;

/**
 * @Author xiaom
 * @Date 2020/9/22 17:13
 * @Version 1.0.0
 * @Description <>
 **/
public class CommentHandler extends AbsHandler {
    public CommentHandler(TaskModel taskModel) {
        super(taskModel);
    }

    @Override
    String getSuccessMessage() {
        JobAccount jobAccount = JSON.parseObject(taskModel.getTaskParam().toString(),JobAccount.class);
        return "账号：" + jobAccount.getAccount() + " 为视频链接:" + jobAccount.getVideoUrl() + " 评论: [" + jobAccount.getComment() + "] 成功";
    }

    @Override
    String getErrorMessage(String errmsg) {
        return null;
    }

    @Override
    public void execute() throws Exception {
        super.execute();
    }

    @Override
    public void responseAfter(AbstractResponse response) {
        JobAccount jobAccount = JSON.parseObject(taskModel.getTaskParam().toString(),JobAccount.class);
        //更新关注数量
        getAccountService().updateCommentCount(jobAccount.getAccount(),1);
    }

    @Override
    CommentResponse requestApi() {
        DyUserServiceImpl dyUserService = SpringContext.getBean(DyUserServiceImpl.class);
        JobAccount jobAccount = JSON.parseObject(taskModel.getTaskParam().toString(),JobAccount.class);

        //获取账号信息
        ImportAccount account = dyUserService.getDyUserInfo(jobAccount.getAccount());
        return getSdkService().executeCommentSdk(jobAccount.getComment(),account.getUrlParam(),account.getHeader(),jobAccount.getVideoUrl(),account.getAreaCode());
    }

    @Override
    public void responseErrAfter(String errMsg) {

    }
}
